home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c
- Subject: Re: my program has a mind of its own (no really)
- Date: 9 Apr 1996 16:00:01 GMT
- Organization: Borland International
- Message-ID: <4ke1i2$j37@druid.borland.com>
- References: <sbb-0904960305370001@ts13-06.upenn.edu>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <sbb-0904960305370001@ts13-06.upenn.edu>, sbb@eniac.seas.upenn.edu
- says...
- >
- >I am writing a program (with cc as compiler) which has a number of arrays,
- >which I have been verry careful to initialize with values, to avoid
- >segmentation faults. The main part of the program is a loop beginning with
- >an fgets statement to read in the next line from a file. Under certain
- >circumstances, the program returns "Segmentation Fault" just as it reaches
- >the beginning of this loop. When I put it a printf statement right before
- >the loop to see how far it actually got, it worked.
- >
- >printf("something\n");
- >
- >When I removed "something", leaving just
- >
- >printf("\n");
- >
- >it gave me a segmentation fault again. I tried the same tactic at the
- >beginning of the loop, and found that the program worked with a long word
- >in the printf statement, but not a short word. Needless to say, I am
- >slightly bewildered by this behavior, as the printf statement, at least to
- >my knowledge, has no effect on my arrrays. If anyone has had a similar
- >experience, or knows what's going on here, I'd be extremely grateful.
-
- These are typical symptoms of a program that contains a bad pointer. Either
- it hasn't been initialized or it points to freed memory. When it seems to work
- it's just that the pointer happens to be pointing to something harmless. This
- kind of problem can be tough to track down. Good luck!
-
-